﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Net;
using TCPSockets;

namespace Galaxy.Portal.TCP
{
    [Serializable]
    internal class CKnownConnection : IPEndPoint, ISerializable
    {
        public CKnownConnection(IPAddress Address, int Port) : base(Address, Port) { }

        protected CKnownConnection(SerializationInfo info, StreamingContext context)
            : base(info.GetValue("Address", typeof(IPAddress)) as IPAddress, info.GetInt32("Port")) { }

        void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Address", this.Address);
            info.AddValue("Port", this.Port);
        }

        public static implicit operator CTCPClient(CKnownConnection Connection)
        {
            return new CTCPClient(Connection.Address.ToString(), Connection.Port);
        }

        public static implicit operator CKnownConnection(CTCPClient Client)
        {
            return new CKnownConnection(IPAddress.Parse(Client.Host), Client.Port);
        }
    }
}
